angular.module('invite', [])
    .controller('inviteCtrl', ['$scope', 'httpService', 'alertmsg', function($scope, httpService, alertmsg) {

        $scope.invitedata = {};
        var i = 1;
        $scope.arrs = [
            { i: 0, name: 'emailinvite0' }
        ];
        $scope.add = function() {
            $scope.arrs.push({ i: i, name: 'emailinvite' + i });
            ++i;
        };

        // 邀请成员
        $scope.isemailform = false;
        $scope.invite = function(bool, invitedata) {
            var arrs = [];
            for (var v in invitedata) {
                arrs.push(invitedata[v]);
            }
            if (!bool) {
                httpService.query('web/users/invite', { users: arrs }, 'post').then(function(res) {
                    if (res.code == 200) {
                        $scope.arrs = [
                            { i: 0, name: 'emailinvite0' }
                        ];
                        $scope.invitedata = {};
                    }
                    alertmsg(res.msg);
                });
            } else {
                $scope.isemailform = true;
            }

        };
    }]);
